package com.sinoglobal.wallet.activity;

import com.lidroid.xutils.BitmapUtils;
import com.sinoglobal.wallet.R;
import com.sinoglobal.wallet.api.RemoteImpl;
import com.sinoglobal.wallet.entity.W_SinoBaseEntity;
import com.sinoglobal.wallet.task.MyAsyncTask;
import com.sinoglobal.wallet.util.NetWorkUtil;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
/**
 * 我的银行卡详情
 * @author lijingjing
 * @createdate 2015-10-22 上午9:33:07
 * @Description: TODO(用一句话描述该类做什么)
 */
public class W_MyBankXQActivity extends W_SinoBaseActivity {
	private TextView bankXQ_name, bankXq_num, bankXq_cardName, 
			bankXq_endNum; // 持卡人 卡号  银行卡名称 尾号
	private ImageView bankXq_img;//卡图标
	private String bankId, bankName, bankIcon, cardSn, cardName;
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.wallet_minebank_xq_activity);
		init();
//		getBankXq();
	}

	private void init(){
		mTemplateRightText.setVisibility(View.VISIBLE);
		mTemplateRightText.setText("解除绑定");
		mTemplateTitleText.setText("我的银行卡");
		mTemplateRightText.setOnClickListener(this);
		bankXQ_name = (TextView) findViewById(R.id.bankXQ_name);
		bankXq_num = (TextView) findViewById(R.id.bankXq_num);
		bankXq_img = (ImageView) findViewById(R.id.bankXq_img);
		bankXq_cardName = (TextView) findViewById(R.id.bankXq_cardName);
		bankXq_endNum = (TextView) findViewById(R.id.bankXq_endNum);
		
		bankId = getIntent().getStringExtra("bankId");
		bankName = getIntent().getStringExtra("bankName");
		bankIcon = getIntent().getStringExtra("bankIcon");
		cardSn = getIntent().getStringExtra("cardSn");
		cardName = getIntent().getStringExtra("cardName");
		
		BitmapUtils bitmapUtils = new BitmapUtils(W_MyBankXQActivity.this);
//		bitmapUtils.configDefaultLoadingImage(R.drawable.ic_launcher);
//		bitmapUtils.configDefaultLoadFailedImage(R.drawable.ic_launcher);
//		if(bankIcon.toString().endsWith("")){
//			bankXq_img.setBackgroundResource(R.drawable.ic_launcher);
//		}
		bitmapUtils.display(bankXq_img, bankIcon);
		bankXq_cardName.setText(bankName);
		bankXq_endNum.setText("(尾号" + cardSn.substring(cardSn.toCharArray().length-4, 
				cardSn.toCharArray().length) + ")");
		String a = "";
		for (int i = 0; i < cardName.length() - 1; i++) {
			a+= "*";
		}
		bankXQ_name.setText(a + cardName.substring(cardName.toCharArray().length-1,cardName.toCharArray().length));
		String s = "";
		for (int i = 0; i < cardSn.length() - 4; i++) {
			s += "*";
		}
		bankXq_num.setText(s + cardSn.substring(cardSn.toCharArray().length-4,cardSn.toCharArray().length));
	}
	
	@Override
	public void onClick(View paramView) {
		int id = paramView.getId();
		if(id == R.id.wallet_title_right_tv){
			showDialog(W_MyBankXQActivity.this, "提示", "确定对这张卡解除绑定吗？","解除绑定",R.color.w_c14, null,R.color.w_c14,true,new DialogOnClickListener() {
				
				@Override
				public void onSure(View v) {
					getDeleteBank();
				}
				
				@Override
				public void onCancle(View v) {
					
//					showToast("取消");
				}
			});
		}else if (id == R.id.wallet_noData) {
			 if(NetWorkUtil.getNetWorkInfoType(getApplicationContext())==NetWorkUtil.NONE){
					showToast("请检查网络是否连接！");	
					 loadError(true);
					}else{
						loadError(false);;
					}
		}
		
	}

	//获取银行卡详情
//	private void getBankXq(){
//		MyAsyncTask<BankXqVo> task = new MyAsyncTask<BankXqVo>(true,this,true) {
//
//			@Override
//			public BankXqVo before(Void... params) throws Exception {
//				// TODO 测试接口
//				return RemoteImpl.getInstance().getBankXQ(MyBankXQActivity.this, bankId);
//			}
//
//			@Override
//			public void after(BankXqVo result) {
//
//				if (result.getCode().equals("100")) {
//					if(result != null){
//						bankXQ_name.setText(result.getCardName());
//						bankXq_num.setText(result.getCardSn());
//					}
//				} else {
//					showToast(result.getMsg());
//				}
//			
//			}
//
//			@Override
//			public void exception() {
//			}
//		};
//		task.execute();
//	}
	
	//删除银行卡
		private void getDeleteBank(){
			MyAsyncTask<W_SinoBaseEntity> task = new MyAsyncTask<W_SinoBaseEntity>(true,this,true) {

				@Override
				public W_SinoBaseEntity before(Void... params) throws Exception {
					// TODO 测试接口
					return RemoteImpl.getInstance().getDeleteBank(W_MyBankXQActivity.this, bankId, "1");
				}

				@Override
				public void after(W_SinoBaseEntity result) {

					if (result.getCode().equals("100")) {
						if(result != null){
							finish();
							showToast("成功解除绑定");
						}
					} else {
						showToast(result.getMsg());
					}
				
				}

				@Override
				public void exception() {
				}
			};
			task.execute();
		}
}
